<template>
	<view class="business">
		<view class="headtop">
			<view class="headtitile">
				<text>商家信息</text>
				<view @click="add">新增</view>
			</view>
		</view>
		<view class="containeradd" v-if="list.length">
			<view class="list clearfix" v-for="(item,index) in list" :key="index" @click="detail(index)">
				<view class="zhuangtai">
					<text v-if="item.type == 1">已到店</text>
					<text v-if="item.type == 2">跟进中</text>
					<text v-if="item.type == 3">无意向</text>
					<text v-if="item.type == 4">有意向</text>
					<text v-if="item.type == 5">已签单</text>
				</view>
				<view class="left fl">
					<image :src="item.shop_photo" class="image"></image>
				</view>
				<view class="right fl">
					<view class="title">{{item.shop_name}}</view>
					<view class="time">{{item.shop_address}}</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else >
			<image src="../../static/images/empty.png" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '@/api/request';

	export default {
		data() {
			return {
				userData: [],
				pageNo: 1,
				list: [],
			}
		},
		created() {
			// 用户基本信息
			request({
				url: '/api/user/profile',
				method: 'GET',
				data: {},
				header: {
					'xx-token': uni.getStorageSync('token')
				}
			}).then((response) => {
				this.userData = response.data;
				
				this.getList(this.pageNo);
			}).catch((error) => {});
			
			let that = this;
			uni.$on('update',function(data){
				that.pageNo = 1;
				that.list = [];
				
				that.getList(that.pageNo);
			})
		},
		methods: {
			getList(pageNo){
				let that = this;
				
				request({
					url: '/api/usergroupbuy/businessinfo_list',
					method: 'POST',
					data: {
						user_id: that.userData.id,
						page: pageNo,
					},
				}).then((response) => {
					if (response.data.list) {
						let list = response.data.list;

						that.list.push(...list);
					}
				}).catch((error) => {});
			},
			detail(index){
				let id = this.list[index].id;
				
				uni.navigateTo({
					url: '/pagesSale/business/detail?id=' + id
				})
			},
			add(){
				uni.navigateTo({
					url: '/pagesSale/business/detail'
				})
			}
		},
	};
</script>

<style scoped lang="scss">
	.business {
		width: 100%;

		.headtop {
			width: 100%;
			margin: 0 auto;
			position: relative;
			height: 166rpx;
			z-index: 200;
		
			.headtitile {
				width: 94%;
				margin: 0 auto;
				position: absolute;
				top: 60rpx;
				left: 3%;
				height: 96rpx;
				line-height: 96rpx;
		
				text {
					font-size: 32rpx;
					color: #FFFFFF;
					float: left;
					height: 96rpx;
					line-height: 96rpx;
				}
		
				view {
					font-size: 30rpx;
					color: #ECDEA4;
					float: right;
					height: 96rpx;
					line-height: 96rpx;
				}
			}
		}
		
		.containeradd {
			width: 94%;
			margin: 0 auto;
			padding-bottom: 120rpx;
		
			.list {
				width: 100%;
				margin-bottom: 20rpx;
				padding: 20rpx;
				box-sizing: border-box;
				background: #242831;
				border-radius: 10rpx;
				position: relative;
		
				.left {
					width: 250rpx;
					height: 140rpx;
					position: relative;
					border-radius: 10rpx;
					margin-right: 20rpx;
		
					.image {
						width: 100%;
						height: 140rpx;
						border-radius: 10rpx;
					}
				}
		
				.right {
					width: 56%;
		
					.title {
						font-size: 30rpx;
						color: #FFFFFF;
						margin-top: 10rpx;
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
		
					.time {
						font-size: 24rpx;
						color: #787B8F;
						margin-top: 20rpx;
						width: 100%;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2; /* 限制行数 */
						overflow: hidden;
					}
				}
				
				.zhuangtai{
					position: absolute;
					top: 0;
					left: 0;
					width: 100rpx;
					text-align: center;
					height: 48rpx;
					line-height: 48rpx;
					color: #806B1A;
					font-size: 24rpx;
					background: linear-gradient(270deg, #EAC59F, #E4B985, #FFF9CE);
					border-radius: 5rpx;
					z-index: 60;
				}
			}
		}

		.empty {
			width: 94%;
			margin: 300rpx auto;
			text-align: center;
		
			image {
				width: 300rpx;
			}
		}
	}
</style>